using System;
using System.Collections.Generic;
using System.Text;

using Csla;
using Csla.Data;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace buildingLib.daily
{
    public class ConsumType:
        NameValueListBase<string, string>
    {
        static ConsumType m_types;
        #region Factory
        public static ConsumType GetFeeTemplates()
        {
            if (m_types == null)
            {
                m_types = DataPortal.Fetch<ConsumType>
          (new Criteria(typeof(ConsumType)));
            }
            return m_types;
        }

        public static void InvalidateCache()
        {
            m_types = null;
        }
        #endregion

        #region Data Access

        private void DataPortal_Fetch(Criteria criteria)
        {
            this.RaiseListChangedEvents = false;
            IsReadOnly = false;
            Database db = SQLDatabase.GetDatabase();
            DbCommand dbcom = db.GetStoredProcCommand("usp_GGetConsumTypes");
            using (SafeDataReader dr = new SafeDataReader(db.ExecuteReader(dbcom)))
            {
                while (dr.Read())
                {
                    this.Add(new NameValueListBase<string, string>.NameValuePair(dr.GetString("type"), dr.GetString("type")));
                }
            }

            IsReadOnly = true;
            this.RaiseListChangedEvents = true;
        }

        #endregion
    }
}
